<%@ page import="com.zou.beans.Photo" %>
<%@ page import="java.util.List" %>
<%@ page import="com.zou.beans.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>相册</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body tr td,th {
            line-height: 50px;
            font-size: 20px;
            text-align: center;
        }

        #a tr:hover {
            background: #D4E3E5;
        }

        img {
            height: 60px;
        }

        body {
            text-align: center;
            background: #cccccc;
        }
    </style>
</head>
<body>
<%
    List<Photo> list = (List<Photo>) request.getAttribute("PhotoList");
    List<Photo> favList = (List<Photo>) request.getAttribute("FavList");
    int count = 0;
    User user = (User) session.getAttribute("User");
    if (user == null) {
        response.sendRedirect("login.jsp");
    }
%>
<!--顶部导航栏部分-->
<nav class="navbar navbar-dark sticky-top bg-success flex-md-nowrap p-0 shadow">
    <a class="navbar-brand col-md-3 col-lg-2 mr-0 px-3"
       href="https://blog.csdn.net/Zou_05">&emsp;&emsp;&emsp;小邹喜欢Java</a>
    <div class="btn-group" style="margin-right: 100px">
        当前用户：<%=user.getName()%>
    </div>
</nav>
<div style="padding: 20px 0 20px 0;text-align: right;margin-right: 100px">
    <a class="btn btn-primary" href="PhotoWallServlet">首页</a>
    <a class="btn btn-info" href="editPhoto.jsp">上传图片</a>
    <a class="btn btn-danger" href="LoginServlet">退出登录</a>
</div>
<h1 style="text-align: center">我的相册</h1>
<table class="table table-hover table-bordered" style="width: 1300px;margin-left: 100px">
    <tr>
        <th>编号</th>
        <th>照片</th>
        <th>描述</th>
        <th>操作</th>
    </tr>

    <%
        for (Photo photo : list) {
            ++count;
    %>
    <tr>
        <td><%=count%>
        </td>
        <%--        <td><img src="<%=photo.getUrl()%>"></td>--%>
        <td>
            <a href="AddPhotoCollectionServlet?photoId=<%=photo.getId()%>&flag=00">
                <img class="img-circle" src="<%=photo.getUrl()%>"></a>
        </td>
        <td><%=photo.getName()%>
        </td>
        <td>
            <a href="editPhoto.jsp?id=<%=photo.getId()%>&name=<%=photo.getName()%>&url=<%=photo.getUrl()%>">修改</a>
            <a href="EditPhotoServlet?PhotoId=<%=photo.getId()%>"
               onclick="return confirm('你确定要删除吗?');">删除</a>
        </td>
    </tr>
    <%
        }
    %>
</table>
<br/>
<h1 style="text-align: center">我的收藏</h1>
<table class="table table-hover table-bordered" style="width: 1300px;margin-left: 100px">
    <tr>
        <th>编号</th>
        <th>照片</th>
        <th>描述</th>
        <th>操作</th>
    </tr>

    <%
        count = 0;
        for (Photo photo : favList) {
            ++count;
    %>
    <tr>
        <td><%=count%>
        </td>
        <td>
            <a href="AddPhotoCollectionServlet?photoId=<%=photo.getId()%>&flag=00">
                <img class="img-circle" src="<%=photo.getUrl()%>"></a>
        </td>
        <td><%=photo.getName()%>
        </td>
        <td>
            <a href="AddPhotoCollectionServlet?photoId=<%=photo.getId()%>&userId=<%=user.getId()%>&flag=11"
               onclick="return confirm('你确定要取消收藏吗?');">取消收藏</a>
        </td>
    </tr>
    <%
        }
    %>
</table>

</body>
</html>
